import { getCurrentInstance, useSlots, type VNode } from "vue";

/**
 * setup()中的渲染钩子函数
 * @param render
 */
export function useRender(render: () => VNode) {
  const vm = getCurrentInstance() as any;
  if (!vm) {
    throw new Error("unknown component !");
  }
  vm.render = render;
}

/**
 * 组件不渲染任何内容
 */
export function useEmptyRender() {
  useRender(() => null as unknown as VNode);
}

/**
 * 组件渲染默认的插槽slots.default()
 */
export function useDefaultRender() {
  const slots = useSlots();
  useRender(() => (slots.default as Function)() as VNode);
}
